namespace YXShop.ExcelLite
{
    using System;
    using System.Drawing;

    public class ExcelFont
    {
        public const int BoldWeight = 700;
        public const int MaxWeight = 0x3e8;
        public const int MinWeight = 100;
        public const int NormalWeight = 400;
        private CellStyle parent;

        internal ExcelFont(CellStyle parent)
        {
            this.parent = parent;
        }

        internal void CopyTo(CellStyle destination)
        {
            destination.Element.FontData = new ExcelFontData(this.parent.Element.FontData);
            destination.UseFlags &= ~CellStyleData.Properties.FontRelated;
            destination.UseFlags |= this.parent.UseFlags & CellStyleData.Properties.FontRelated;
        }

        public System.Drawing.Color Color
        {
            get
            {
                return this.parent.Element.FontData.Color;
            }
            set
            {
                this.parent.BeforeChange();
                this.parent.Element.FontData.Color = value;
                this.parent.UseFlags |= CellStyleData.Properties.FontColor;
            }
        }

        public bool Italic
        {
            get
            {
                return this.parent.Element.FontData.Italic;
            }
            set
            {
                this.parent.BeforeChange();
                this.parent.Element.FontData.Italic = value;
                this.parent.UseFlags |= CellStyleData.Properties.FontItalic;
            }
        }

        public string Name
        {
            get
            {
                return this.parent.Element.FontData.Name;
            }
            set
            {
                this.parent.BeforeChange();
                this.parent.Element.FontData.Name = value;
                this.parent.UseFlags |= CellStyleData.Properties.FontName;
            }
        }

        public YXShop.ExcelLite.ScriptPosition ScriptPosition
        {
            get
            {
                return this.parent.Element.FontData.ScriptPosition;
            }
            set
            {
                this.parent.BeforeChange();
                this.parent.Element.FontData.ScriptPosition = value;
                this.parent.UseFlags |= CellStyleData.Properties.FontScriptPosition;
            }
        }

        public int Size
        {
            get
            {
                return this.parent.Element.FontData.Size;
            }
            set
            {
                this.parent.BeforeChange();
                this.parent.Element.FontData.Size = value;
                this.parent.UseFlags |= CellStyleData.Properties.FontSize;
            }
        }

        public bool Strikeout
        {
            get
            {
                return this.parent.Element.FontData.Strikeout;
            }
            set
            {
                this.parent.BeforeChange();
                this.parent.Element.FontData.Strikeout = value;
                this.parent.UseFlags |= CellStyleData.Properties.FontStrikeout;
            }
        }

        public YXShop.ExcelLite.UnderlineStyle UnderlineStyle
        {
            get
            {
                return this.parent.Element.FontData.UnderlineStyle;
            }
            set
            {
                this.parent.BeforeChange();
                this.parent.Element.FontData.UnderlineStyle = value;
                this.parent.UseFlags |= CellStyleData.Properties.FontUnderlineStyle;
            }
        }

        public int Weight
        {
            get
            {
                return this.parent.Element.FontData.Weight;
            }
            set
            {
                if ((value < 100) || (value > 0x3e8))
                {
                    throw new ArgumentOutOfRangeException("value", value, "Font weight is out of allowed range.");
                }
                this.parent.BeforeChange();
                this.parent.Element.FontData.Weight = value;
                this.parent.UseFlags |= CellStyleData.Properties.FontWeight;
            }
        }
    }
}

